"""
@name : 02.psutil
@author : wenyao
@projectname: xsfh
"""

#1、统计当前cpu的逻辑个数，显示平均利用率
#2、显示总内存大小、以及内存使用率
#3、显示根目录大小，以及根目录使用率
#4、显示你的网卡信息（ip）
#把你电脑上的这些信息都发送邮件给我（343292019@qq.com）


from smtplib import SMTP
from email.mime.text import MIMEText

import psutil

mailhost = 'smtp.163.com'
mailuser = 'EXP2020520@163.com'
mailpass = 'VVTOVUEQCHVUPAQP'
recvmail = '343292019@qq.com'
cpucount=psutil.cpu_count()
cpupercet=("{0}%".format(int(psutil.cpu_percent()*100)))
totalmemory=("{0}Mb".format(int(((psutil.virtual_memory().total))/1024/1024)))
memorypercent=("{0}%".format(int(psutil.virtual_memory().percent)))
rootdisk=("{0}Mb".format((int(((psutil.disk_usage('/').total))/1024/1024))))
rootpercent=("{0}%".format(int(psutil.disk_usage('/').percent)))
ipaddr=psutil.net_if_addrs().get('以太网')[1][1]
pcmsg = ("cpucount:{0} \ncpupercent:{1} \ntotalmemory:{2} \nmemorypercent:{3} \nrootdisk:{4} \nrootpercent:{5} \nipaddress:{6}".format(cpucount,cpupercet,totalmemory,memorypercent,rootdisk,rootpercent,ipaddr))
print(pcmsg)
msg = MIMEText(pcmsg)
msg['From'] = mailuser
msg['To'] = recvmail
msg['Subject'] = 'PC INFO'
s = SMTP(mailhost)
s.login(mailuser, mailpass)
s.sendmail(mailuser, recvmail, msg.as_string())